package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import been.User;

/**
 * Servlet implementation class json
 */
public class json extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public json() {
        super();
        // TODO Auto-generated constructor stub
    }

	public String getString(){
		List<User> list = new ArrayList<User>();
		User u = new User("aqia","358");
		list.add(u);
		User u1 = new User("aqia1","3581");
		list.add(u1);
		User u2 = new User("aqia2","358");
		list.add(u2);
		User u3 = new User("aqia3","358");
		list.add(u3);
		JSONArray listBeen = JSONArray.fromObject(list);
		for(int i = 0;i < listBeen.size(); i++){
			User uu = new User();
			JSONObject a = listBeen.getJSONObject(i);//�ѵõ���JSONObject�ֳɵ����JSONObject
			uu = (User)JSONObject.toBean(a,User.class);//�ѵ����JSONObjectת��been
			System.out.println(a);
		}
		String str = listBeen.toString();
		System.out.println(listBeen);
		System.out.println(str);
		return str;
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		System.out.println("servlet");
		out.println(getString());
		out.flush();
		out.close();
	}
 
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);

	}

}
